package com.vcc.web.controller;


import cn.dev33.satoken.annotation.SaCheckLogin;
import com.mybatisflex.core.paginate.Page;
import com.vcc.core.annotations.RestPack;
import com.vcc.data.entity.Notice;
import com.vcc.service.client.vo.notice.NoticeVo;
import com.vcc.service.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("notice")
public class NoticeController {

    @Autowired
    private NoticeService noticeService;

    @RestPack
    @GetMapping("paging")
    public Page<NoticeVo> paging(
            Integer pageNumber,
            Integer pageSize,
            String title
    ) {

        Page<Notice> paging = noticeService.paging(
                Page.of(
                        pageNumber == null ? 1 : pageNumber,
                        pageSize == null ? 5 : pageSize
                ),
                title
        );
        return paging.map(NoticeVo::new);
    }

    @RestPack
    @GetMapping("listPopup")
    @SaCheckLogin
    public List<NoticeVo> listPopup(
    ) {
        List<Notice> notices = noticeService.listPopup();
        return notices.stream().map(NoticeVo::new).toList();
    }

}
